package com.mwcz.hot.finance.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.common.PageParamRequest;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mwcz.hot.finance.dao.UserFundsMonitorDao;
import com.mwcz.hot.finance.model.UserFundsMonitor;
import com.mwcz.hot.finance.request.FundsMonitorUserSearchRequest;
import com.mwcz.hot.finance.service.UserFundsMonitorService;
import com.mwcz.hot.user.model.UserBrokerageRecord;
import com.mwcz.hot.user.service.UserBrokerageRecordService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * UserRechargeServiceImpl 接口实现
 * +----------------------------------------------------------------------

 * +----------------------------------------------------------------------
 */
@Service
public class UserFundsMonitorServiceImpl extends ServiceImpl<UserFundsMonitorDao, UserFundsMonitor> implements UserFundsMonitorService {

    @Resource
    private UserFundsMonitorDao dao;

    @Autowired
    private UserBrokerageRecordService userBrokerageRecordService;

    /**
     * 佣金列表
     *
     * @return List<User>
     * @author Mr.Bai
     * @since 2021-06-18
     */
    @Override
    public List<UserFundsMonitor> getFundsMonitor(FundsMonitorUserSearchRequest request, PageParamRequest pageParamRequest) {
        PageHelper.startPage(pageParamRequest.getPage(), pageParamRequest.getLimit());
        HashMap<String, Object> map = new HashMap<>();
        String keywords = null;
        if (!StringUtils.isBlank(request.getKeywords())) {
            keywords = "%" + request.getKeywords() + "%";
        }
        map.put("keywords", keywords);
        map.put("max", request.getMax());
        map.put("min", request.getMin());
        String sort = "desc";
        if (!StringUtils.isBlank(request.getSort())) {
            sort = request.getSort();
        }
        map.put("sort", sort);
        List<UserFundsMonitor> monitorList = dao.getFundsMonitor(map);
        return monitorList;
    }

    /**
     * 佣金详细记录
     *
     * @param uid              用户uid
     * @param pageParamRequest 分页参数
     * @return
     */
    @Override
    public PageInfo<UserBrokerageRecord> getFundsMonitorDetail(Integer uid, String dateLimit, PageParamRequest pageParamRequest) {
        return userBrokerageRecordService.getFundsMonitorDetail(uid, dateLimit, pageParamRequest);
    }


}

